package com.aya.aopx.invalid;

import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.Pointcut;
import org.springframework.aop.PointcutAdvisor;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.stereotype.Service;

@Service
public class CustomAdvisor implements PointcutAdvisor {

    @Override
    public Pointcut getPointcut() {
        AspectJExpressionPointcut aspectJExpressionPointcut = new AspectJExpressionPointcut();
        aspectJExpressionPointcut.setExpression("execution(public * com.aya.aopx.invalid..*(..))");
        return aspectJExpressionPointcut;
    }

    private static final Logger logger = LoggerFactory.getLogger(CustomAdvisor.class);

    @Override
    public Advice getAdvice() {
        return (MethodInterceptor) invocation -> {
            logger.info("advisor visited");
            return invocation.proceed();
        };
    }

    @Override
    public boolean isPerInstance() {
        return false;
    }
}
